package com.project.srtp.common.convention;

import com.project.srtp.common.result.errorcode.ResultCode;
import org.hibernate.service.spi.ServiceException;
import org.springframework.util.StringUtils;

import java.util.Optional;

/**
 * 抽象项目中三类异常体系，客户端异常、服务端异常以及远程服务调用异常
 *
 * @see ClientException
 * @see ServiceException
 * @see RemoteException
 */
public abstract class AbstractException extends RuntimeException {

    public final int errorCode;

    public final String errorMessage;


    public AbstractException(String message, Throwable throwable, ResultCode code) {
        super(message, throwable);
        this.errorCode = code.code();
        this.errorMessage = Optional.ofNullable(StringUtils.hasLength(message) ? message : null).orElse(code.message());
    }
}
